package com.tanhua.server.controller;

import com.tanhua.server.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessageController {

    @Autowired
    private MessageService messageService;

    /**
     * 聊天-添加联系人
     * POST/messages/contacts
     */
    @PostMapping("/contacts")
    public ResponseEntity addContact(@RequestBody Map map){
        Long targetUserId = Long.parseLong(map.get("userId").toString());
        return messageService.addContact(targetUserId);
    }
    @GetMapping("/contacts")
    public ResponseEntity findContactList(@RequestParam(defaultValue = "1") int page,
                                          @RequestParam(defaultValue = "10") int pagesize,
                                          @RequestParam(required = false)String keyword) {
        return messageService.findContactList(page, pagesize, keyword);
    }

    /**
     * 消息-公告列表
     * GET/messages/announcements
     */
    @GetMapping("/announcements")
    public ResponseEntity findAnnouncementList(@RequestParam(defaultValue = "1")int page,
                                               @RequestParam(defaultValue = "10")int pagesize){
        return messageService.findAnnouncementList(page,pagesize);
    }
}